﻿using BLL;
using Model;
using System;

namespace Thksoft.UserCotrols
{
    public partial class CtrlUrgentEdit : System.Web.UI.UserControl
    {
        private QS_URGENTFUNDSAPPLYBLL urgBll = new QS_URGENTFUNDSAPPLYBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string busId = Request.QueryString["BusinessId"].ToString();

                hidId.Value = busId;

                Bind();
            }
        }

        public void Bind()
        {
            QS_URGENTFUNDSAPPLY model = urgBll.Find(hidId.Value);

            if (model != null)
            {
                FORM_COMPANY_ID.Value = model.N_COMPANY_ID;
                txturgDate.Value = model.D_DATA.ToString("yyyy-MM-dd");
                txtTitle.Value = model.C_TITLE;

                txtDfzh.Value = model.C_ACCOUNT;
                txtDfzhName.Text = model.C_ACCOUNT_NAME;
                txtamont1.Value = model.N_AMOUNT.ToString();

                Text1.Value = model.C_EVENT;
                txtRemark.Text = model.C_REMARK;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (FORM_COMPANY_ID.Value == -1)
            {
                MessageBox.Show(Page, "请选择公司");
                return;
            }

            if (txturgDate.Value.Trim() == "")
            {
                MessageBox.Show(Page, "请选择日期");
                return;
            }

            if (txtTitle.Value.Trim() == "")
            {
                MessageBox.Show(Page, "请填写业务名称");
                return;
            }

            if (txtDfzh.Value.Trim() == "")
            {
                MessageBox.Show(Page, "请输入对方账户");
                return;
            }

            if (txtDfzhName.Text.Trim() == "")
            {
                MessageBox.Show(Page, "请输入对方账户名称");
                return;
            }

            if (txtamont1.Value.Trim() == "")
            {
                MessageBox.Show(Page, "请输入打款金额");
                return;
            }

            QS_URGENTFUNDSAPPLY model = new QS_URGENTFUNDSAPPLY();

            model.N_BUSINESS_ID = decimal.Parse(hidId.Value);
            model.N_AMOUNT = decimal.Parse(txtamont1.Value.Trim());
            model.C_ACCOUNT = txtDfzh.Value.Trim();
            model.C_ACCOUNT_NAME = txtDfzhName.Text.Trim();
            model.C_TITLE = txtTitle.Value.Trim();

            model.C_EVENT = Text1.Value.Trim();
            model.D_DATA = DateTime.Parse(txturgDate.Value);

            model.C_REMARK = txtRemark.Text.Trim();

            int count = urgBll.Update(model, "");

            if (count > 0)
            {
                MessageBox.Show(Page, "修改成功！");
            }
            else
            {
                MessageBox.Show(Page, "修改失败！");
            }
        }
    }
}